$("#dialog-confirm").dialog({
	autoOpen : false,
	height : 150,
	width : 400,
	modal : true,
	buttons : {
		"确定删除" : function() {
			var param = {
				"seq" : $("#seq").val()
			};
			API.deleteDiMedicineGroup(param, function(res) {
				if (res.code == '0') {
					window.location.reload();
				} else {
					alert(res.desc);
					window.location.reload();
				}
			});
		},
		Cancel : function() {
			$(this).dialog("close");
		}
	}
});

function deleteDiMedicineGroup(seq) {
	$("#seq").val(seq);
	$("#dialog-confirm").dialog("open");
}

$("#importing").button().hide();
$("#import").button().click(function(){
	$("#file").click();
});
$("#file").change(function(){
	$("#importing").button().show();
	$("#import").button().hide();
	var url ="/medicine/import_di_medicine_group.do";
	importFile("#file",url,null);
});	

function exportTxt() {
	window.location.href = "/medicine/export_di_medicine_group.do";
}
$("#export").button().click(exportTxt);

function preUpdate(obj) {
	$(obj).hide();
	$(obj).next("input").show();
	$(obj).next("input").focus();
}

function update(obj) {

	var param = {
		seq : $(obj).attr("dataid")
	};
	
	if ($(obj).attr("id") == "updateId") {
		param.id = $(obj).val();
	}

	if ($(obj).attr("id") == "updateDi") {
		param.di = $(obj).val();
	}

	if ($(obj).attr("id") == "updateRank") {
		param.rank = $(obj).val();
	}

	if ($(obj).attr("id") == "updateAge") {
		param.age = $(obj).val();
	}
	
	if ($(obj).attr("id") == "updateSex") {
		param.sex = $(obj).val();
	}

	API.updateDiMedicineGroup(param, function(res) {
		UTIL.releaseButton(obj);
		if (res.code == '0') {
			window.location.reload();
		} else {
			alert(res.desc);
			window.location.reload();
		}
	});
}

